using UnityEngine;
using UnityEngine.UI;

public class AudioControl : MonoBehaviour
{
	public Sprite onSprite;

	public Sprite offSprite;

	public Image image;

	private void Awake()
	{
		AudioListener.volume = DO.Player.audioVolume;
		UpdateImage();
	}

	public void Switch()
	{
		if (AudioListener.volume == 0f)
		{
			AudioListener.volume = 1f;
		}
		else
		{
			AudioListener.volume = 0f;
		}
		DO.Player.audioVolume = AudioListener.volume;
		string content = JsonUtility.ToJson(DO.Player);
		SaveLoad.SaveString("Player", content);
		UpdateImage();
	}

	public void UpdateImage()
	{
		if (AudioListener.volume == 0f)
		{
			image.sprite = offSprite;
		}
		else
		{
			image.sprite = onSprite;
		}
	}
}
